<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>不合格处置</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/assets/ztree/css/zTreeStyle/zTreeStyle.css">
	
	<script type="text/javascript" src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.all.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.core.js"></script>  
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.excheck.js"></script>  
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.exedit.js"></script>
	<style type="text/css">
		#addFormId .layui-form-label{
			padding: 9px 15px 9px 0 !important;
			width:auto !important;
		}
	</style>
</head>
<body>
<!-- 上表 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">  批量删除</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="approve"><i class="layui-icon layui-icon-release">  发起审批</i></button>
	</div>
</script>
<h2 style="text-align: center;color:#666">处置单</h2>
<table class="layui-hide" id="disposeRejects" lay-filter="disposeRejects"></table>
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 隐藏域 -->
<input id="dIdText" type="text" class="layui-hide">
<!-- 下表 -->
<h2 style="text-align: center;color:#666" class="layui-hide" id="detailsTitle">处置单详情</h2>
<table class="layui-hide" id="disposeRejectsDetails" lay-filter="disposeRejectsDetails"></table>
<script type="text/html" id="barDemoDetails">
	<a class="layui-btn layui-btn-xs" lay-event="checkDetails">检测结果</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delDetails">删除</a>
</script>
<form class="layui-form layui-card-body" id="addFormId" hidden>
	<table class="layui-table" id="tab">
		<thead>
			<tr>
				<th>序号</th>
				<th>质检单号</th>
				<th>名称</th>
				<th>条码</th>
				<th>工位</th>
				<th>报检日期</th>
				<th>检验日期</th>
				<th>检验人</th>
				<th>数目</th>
				<th>检验结果</th>
				<th width="120px">操作</th>
			</tr>
		</thead>
		<tbody id="tbody">
    			<tr id="tr1">
    				<td align="center">1</td>
					<td><input class="layui-input" readonly id="ddNumber1" name="ddNumber" onclick="selectByDdNumber(1)"/></td>
					<td><input class="layui-input" readonly id="ddName1" name="ddName"/></td>
					<td><input class="layui-input" readonly id="remark011" name="remark01"/></td>
					<td><input class="layui-input" readonly id="remark021" name="remark02"/></td>
					<td><input class="layui-input" readonly id="insDate1" name="insDate"/></td>
					<td><input class="layui-input" readonly id="testDate1" name="testDate"/></td>
					<td><input class="layui-input" readonly id="testPerson1" name="testPerson"/></td>
					<td><input class="layui-input" readonly id="badNum1" name="badNum"/></td>
					<td><input class="layui-btn" type="button" id="testDetails1" value="检测结果"/></td>
					<td>
						<input style="font-size: 15px" type="button" class="layui-btn" id="add" value="＋">
					</td>
    			</tr>
    		</tbody>
	</table>
	<label class="layui-form-label">处置结果</label>
	<div class="layui-inline" style="width:300px">
		<select class="layui-select" lay-verify="" id="dWay" name="dWay">
			<option value="返工">返工</option>
			<option value="降级">降级</option>
			<option value="让步接收">让步接收</option>
			<option value="报废">报废</option>
		</select>
	</div>
	<button  lay-submit id="subBtn" class="layui-btn layui-btn-blue layui-inline" lay-filter="addform">提交</button>
	<button type="reset" id="addReset" class="layui-btn layui-btn-primary layui-hide" >重置</button>
</form>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
//日期格式转换
function createTime(v){
	var date = new Date(v);
    var y = date.getFullYear();
    var M = date.getMonth()+1;
    M = M<10?'0'+M:M;
    var d = date.getDate();
    d = d<10?("0"+d):d;
    var h = date.getHours();
    h = h<10?("0"+h):h;
    var m = date.getMinutes();
    m = m<10?("0"+m):m;
    var str = y+"-"+M+"-"+d+" "+h+":"+m;
    return str;
}
//日期格式转换
function date2String(timestamp){
	var d = new Date(timestamp);
	var date = (d.getFullYear()) + "-" + 
       (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
       (d.getDate()<10?"0"+d.getDate():d.getDate()) + " " + 
       (d.getHours()<10?"0"+d.getHours():d.getHours()) + ":" + 
       (d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes()) + ":" + 
       (d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds());
       
       return date;
}

layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				table.reload('contenttable',{
					method:'get',
					where:{keyword:keyword}
					,page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#disposeRejects'
	    ,url:'${pageContext.request.contextPath }/disposeRejects/selectDisposeRejectsList.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '不合格处置单'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
		  {type: 'checkbox', fixed: 'left',width:50}
		  ,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
	      ,{field:'dNumber', title:'处置单号'}
	      ,{field:'dWay', title:'处置结果',sort:true}
	      ,{field:'dDisponer', title:'处置人'}
	      ,{field:'dDisposeDate', title:'处置日期',templet:function(row){
	    	  return createTime(row.dDisposeDate.time);
	      }}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:150}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件
	table.on('toolbar(disposeRejects)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['95%', '600px'] //宽  高
					  ,title: '新增'
					  ,shade: 0.1 	//遮罩透明度
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: $("#addFormId")
					  ,success:function(layero, index){
						  $("#addReset").click();
		  	              $("#tbody").find("tr").not(":first").remove();
							//增加行删除行
						 	var index1;
						 	$("body").on("click", "#add", function() {
							var tbody = document.getElementById("tbody");
							index1 = tbody.rows.length + 1
							$("#tbody").append(
									'<tr id="tr'+index1+'">'+
										'<td align="center">'+index1+'</td>'+
										'<td><input class="layui-input" readonly id="ddNumber'+index1+'" name="ddNumber" onclick="selectByDdNumber('+index1+')"/></td>'+
										'<td><input class="layui-input" readonly id="ddName'+index1+'" name="ddName"/></td>'+
										'<td><input class="layui-input" readonly id="remark01'+index1+'" name="remark01"/></td>'+
										'<td><input class="layui-input" readonly id="remark02'+index1+'" name="remark02"/></td>'+
										'<td><input class="layui-input" readonly id="insDate'+index1+'" name="insDate"/></td>'+
										'<td><input class="layui-input" readonly id="testDate'+index1+'" name="testDate"/></td>'+
										'<td><input class="layui-input" readonly id="testPerson'+index1+'" name="testPerson"/></td>'+
										'<td><input class="layui-input" readonly id="badNum'+index1+'" name="badNum"/></td>'+
										'<td><input class="layui-btn" type="button" id="testDetails'+index1+'" value="检测结果"/></td>'+
										'<td>'+
											'<input style="font-size: 15px" type="button" class="layui-btn" id="add" value="＋">'+
						   					'<input style="font-size: 15px" type="button" class="layui-btn" id="recover" value="－">'+
										'</td>'+		
									'</tr>'
								)
						})
						$("body").on("click", "#recover", function() {
						          var rowId = $(this).parents('tr').attr("id");
						          $("#"+rowId).remove();
						})
						form.render();
					  }
		    		,end: function () {
	  	              	$("#addFormId").css("display","none");
	  	              	window.location.reload();
	  	          	}
				});
	      	break;
	    	case 'delete':
	        	var data = checkStatus.data;
	        	var idArr = new Array();
	        	if(data.length==0){
	        		toastr.warning("请至少选择一条记录！");
	        	}
	        	var idArr = new Array();
	        	for(var i=0;i<data.length;i++){
	        		idArr[i] = data[i].dId;
	    		    layer.confirm('确定删除吗？', function(index){
	    			    $.ajax({
	    			    	type:'post',
	    			    	url:'${pageContext.request.contextPath }/disposeRejects/delDisposeRejectsArr.do',
	    			    	data:{"idArr":idArr},
	    			    	success:function(num){
	    			    		if(num>0){
	    			    			toastr.success("删除了"+num+"条数据！");
	    			    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
	    								//关闭模态框
	    								// 父页面刷新
	    								window.location.reload();  
	    							},2000);
	    			    		}else{
	    			    			toastr.warning("删除失败！");
	    			    		}
	    			    	}
	    			    		
	    			    })
	    			    layer.close(index);
	    			  });
	        	}
	      	break;
	    	case 'approve':
	    		var data = checkStatus.data;
	        	var id = data[0].dId;
	        	if(data.length!=1){
	        		toastr.warning("请选择一条数据！");
	        	}else if(data[0].dApproverStatus != 0){
	    			toastr.warning("不能重复发起审批！");
	    		}else{
	    			$.ajax({
	    				type:'post'
	    				,url:'${pageContext.request.contextPath }/disposeRejects/selectHistoryApprover.do'
	    				,dataType:'json'
	    				,success:function(data){
	    					var dApprover = '';
	    					var dCopyMen = '';
	    					//alert(data.dApprover1)
	    					if(data.dApprover1!='undefined'&&data.dApprover1!=''&&data.dApprover1!=null){
		    					dApprover = data.dApprover1+','+data.dApprover2+','+data.dApprover3;
	    					}
	    					if(data.dCopyMen!='undefined'&&data.dCopyMen!=''&&data.dCopyMen!=null){
		    					dCopyMen = data.dCopyMen;
	    					}
			    			var content = '<form class="layui-form layui-card-body">'+
												'<input id="idApprover" style="display:none" value="'+id+'">'+
												'<div class="layui-form-item"><label class="layui-form-label">审批人</label><input readonly class="layui-input" lay-verify="dApprover" placeholder="请分别选择三级审批人" id="dApprover" type="text" value="'+dApprover+'" style="width:300px;display:inline">&emsp;<i style="font-size:22px;" id="refresh" class="layui-icon layui-icon-refresh"></i></div>'+
												'<div id="treeContainer" class="layui-input-block">'+
										    	'<ul id="treeConfig" class="ztree"></ul>'+
												'</div>'+
												'<div class="layui-form-item"><label class="layui-form-label">抄送人</label><input readonly class="layui-input" lay-verify="dCopyMen" placeholder="请选择抄送人" id="dCopyMen" type="text" value="'+dCopyMen+'" style="width:300px;display:inline">&emsp;<i style="font-size:22px;" id="dCopyMenRefresh" class="layui-icon layui-icon-refresh"></i></div>'+
												'<div id="dCopyMenContainer" class="layui-input-block">'+
											    	'<ul id="dCopyMenConfig" class="ztree"></ul>'+
												'</div>'+
												'<div class="layui-form-item"><div class="layui-input-block">'+
												'<button class="layui-btn" type="button" id="sponsorBtn" onclick="sponsor()">发起</button><button type="reset" id="addReset3" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
												'</div></div>'+
										'</form>';
							layer.open({
					            type: 1 					//Page层类型
					            ,area: ['500px', '620px']   //宽  高
					            ,title: '发起审批'
					            ,shade: 0.6 				//遮罩透明度
					            ,maxmin: true			    //允许全屏最小化
					            ,anim: 1 					//0-6的动画形式，-1不开启
					            ,content: content
					            ,success:function(layero, index){
									  form.render();
									  $("#refresh").click(function(){
										  $("#dApprover").val("");
									  })
									  $("#dCopyMenRefresh").click(function(){
										  $("#dCopyMen").val("");
									  })
									  var setting = {  
										        isSimpleData : true,              //数据是否采用简单 Array 格式，默认false  
										        treeNodeKey : "id",               //在isSimpleData格式下，当前节点id属性  
										        treeNodeParentKey : "pId",        //在isSimpleData格式下，当前节点的父节点id属性  
										        showLine : true,                  //是否显示节点间的连线  
										        checkable : true,                  //每个节点上是否显示 CheckBox  
										        data: {  
								                    simpleData: {  
								                       enable: true,  
								                       idKey: "id",  
								                       pIdKey: "pId",  
								                       rootPid: "0"  
								                    }  
								                }, 
										        callback: {
										        	onDblClick: onDblClick,
										        }
										};
								    	$.ajax({
								    		type:'get',
								    		url:'${pageContext.request.contextPath }/disposeRejects/getZtreeJson.do',
								    		dataType:'json',
								    		success: function(data){
								    	    	//alert(JSON.stringify(data.rows[1].pId))
								    			var	zNodes = data.rows;
								    			$(document).ready(function() {
								    	    		//alert(1)
								    		        $.fn.zTree.init($("#treeConfig"), setting, zNodes);
								    		    });
								    		},
								    		error: function(){
								    			toastr.error("请求失败");
								    		}
								    	});
								    	function onDblClick(e,treeId,treeNode) {
									    	selectedNode = treeNode;
									    	var name = treeNode.name;
									    	var id = treeNode.id;
									    	var type = treeNode.type;
									    	if(type!="-1"){
										    	var dApprover1 = $("#dApprover").val();
										    	var dApprovers = dApprover1.split(",");
										    	for(var i=0;i<dApprovers.length;i++){
										    		if(name==dApprovers[i]){
										    			toastr.warning("选择了重复的审批人！")
										    			name="";
										    		}
										    	}
										    	var dApprover2;
										    	if(dApprover1 == "" && name != ""){
											    	dApprover2 = $("#dApprover").val((dApprover1+','+name).substring(1));
										    	}else if(name != ""){
										    		dApprover2 = $("#dApprover").val(dApprover1+','+name);
										    	}
										    	var dApprover3 =  $("#dApprover").val();
										    	var dApprovers3 = dApprover3.split(",");
										    	var dApprovers3Length = dApprovers3.length;
										    	if(dApprovers3Length>3){
										    		toastr.warning("最多选择3个审批人");
										    		$("#dApprover").val(dApprover1);
										    	}
									    	}else{
									    		toastr.warning("请选择审批人！")
									    	}
									    }
								    	var dCopyMenSetting = {
										        isSimpleData : true,              //数据是否采用简单 Array 格式，默认false  
										        treeNodeKey : "id",               //在isSimpleData格式下，当前节点id属性  
										        treeNodeParentKey : "pId",        //在isSimpleData格式下，当前节点的父节点id属性  
										        showLine : false,                  //是否显示节点间的连线  
										        //checkable : true,                  //每个节点上是否显示 CheckBox  
										        data: {  
								                    simpleData: {  
								                       enable: true,  
								                       idKey: "id",  
								                       pIdKey: "pId",  
								                       rootPid: "0"  
								                    }  
								                }, 
										        callback: {
										        	onDblClick: dCopyMenOnDblClick,
										        }
											};
								    	$.ajax({
								    		type:'get',
								    		url:'${pageContext.request.contextPath }/disposeRejects/getZtreeJson.do',
								    		dataType:'json',
								    		success: function(data){
								    	    	//alert(JSON.stringify(data.rows[1].pId))
								    			var	dCopyMenzNodes = data.rows;
								    			$(document).ready(function() {
								    	    		//alert(1)
								    		        $.fn.zTree.init($("#dCopyMenConfig"), dCopyMenSetting, dCopyMenzNodes);
								    		    });
								    		},
								    		error: function(){
								    			toastr.error("请求失败");
								    		}
								    	});
								    	function dCopyMenOnDblClick(e,treeId,treeNode) {
								    		dCopyMenSelectedNode = treeNode;
									    	var name = treeNode.name;
									    	var id = treeNode.id;
									    	var type = treeNode.type;
									    	
									    	var dCopyMen = $("#dCopyMen").val();
									    	var dCopyMen = dCopyMen.split(",");
									    	for(var i=0;i<dCopyMen.length;i++){
									    		if(name==dCopyMen[i]){
									    			toastr.warning("选择了重复的抄送人！")
									    			name="";
									    		}
									    	}
									    	if(dCopyMen == "" && name != ""){
									    		dCopyMen = $("#dCopyMen").val((dCopyMen+','+name).substring(1));
									    	}else if(name != ""){
									    		dCopyMen = $("#dCopyMen").val(dCopyMen+','+name);
									    	}
										}
					            }
							})
	    				}
	    			})
	    		}
	    	break;
	    };
	});
  
	//监听行工具事件
	table.on('tool(disposeRejects)', function(obj){
		var data = obj.data;
		if(obj.event === 'del'){
		  layer.confirm('确定删除吗？', function(index){
			var idArr = new Array();
		    var dId = data.dId;
		    idArr[0] = dId;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/disposeRejects/delDisposeRejectsArr.do',
		    	data:{"idArr":idArr},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		} 
	});
	
	//监听行单击事件(子表)
	 table.on('row(disposeRejects)', function(obj){
		$("#detailsTitle").removeClass("layui-hide");
		var dId = obj.data.dId;
		$("#dIdText").val(dId);
	  	table.render({
		    elem: '#disposeRejectsDetails'
		    ,url:'${pageContext.request.contextPath }/disposeRejects/selectDisposeRejectsDetailsListBydId.do'
		    ,where:{dId: dId}
		    ,toolbar: '#toolbarDemoDetails'
		    ,title: '不合格处置详情表'
		    ,limits:[10,20,30]
		    ,cols: [[
		    	{field:'ddNumber', title:'质检单号' }
			     ,{field:'ddName', title:'名称'}
			     ,{field:'remark01', title:'条码'}
			     ,{field:'insDate', title:'报检日期',templet:function(row){
			    	  return createTime(row.insDate);
			      }}
			     ,{field:'testDate', title:'检验日期',templet:function(row){
			    	  return createTime(row.testDate);
			      }}
			     ,{field:'badNum', title:'数量'}
			     ,{field:'remark02', title:'工位来源'}
			     ,{fixed: 'right', title:'操作', toolbar: '#barDemoDetails'}
		    ]]
		    ,page: true
		});
	});
	//监听行工具事件（子表）
	table.on('tool(disposeRejectsDetails)', function(obj){
		var data = obj.data;
		if(obj.event === 'checkDetails'){
		    var tStation = data.remark02;
		    var tNumber = data.ddNumber;
		    if(tStation=="检漏工位"){
				layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="evResult" lay-filter="evResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#evResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectLeakHuntingListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'number', title:'质检单号'}
				                        ,{field:'lhCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'bDlNumBig', title:'B面堵漏个数大'}
				                        ,{field:'bDlNumSmall', title:'B面堵漏个数小'}
				                        ,{field:'aDlNumBig', title:'A面堵漏个数大'}
				                        ,{field:'aDlNumSmall', title:'A面堵漏个数小'}
				                        ,{field:'aCount', title:'A面总数'}
				                        ,{field:'bCount', title:'B面总数'}
				                        ,{field:'isNormal', title:'检漏是否正常'}
				                        ,{field:'dmbj', title:'端面补胶'}
				                        ,{field:'describe', title:'非正常问题描述'}
				                        ,{field:'lhResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
			}
			else if(tStation=="组件评价工位"){
				layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="evResult" lay-filter="evResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#evResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectEvaluateListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'', title:'序号', sort: true, type:'numbers', width: 60}
				                        ,{field:'number', title:'质检单号'}
				                        ,{field:'evCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'yxsw', title:'运行水温'}
				                        ,{field:'jsyl', title:'进水压力'}
				                        ,{field:'csyl', title:'产水压力'}
				                        ,{field:'nsyl', title:'浓水压力'}
				                        ,{field:'cstl', title:'产水通量'}
				                        ,{field:'nstl', title:'浓水通量'}
				                        ,{field:'yxTime', title:'运行时间'}
				                        ,{field:'evResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
			}else if(tStation=="气密性检测工位"){
				layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="gResult" lay-filter="gResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#gResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectGasListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'', title:'序号', sort: true, type:'numbers', width: 60}
				                        ,{field:'number', title:'质检单号'}
				                        ,{field:'gCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'gIntervalTime', title:'出泡间隔时间',templet:function(row){
				                        	if(row.gIntervalTime==0){
				                        		return "其他";
				                        	}else {
				                        		return row.gIntervalTime;
				                        	}
				                        }}
				                        ,{field:'gResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
			}else{
				layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="testResult" lay-filter="testResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#testResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectTestListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'', title:'序号', sort: true, type:'numbers', width: 60}
				                        ,{field:'tNumber', title:'质检单号'}
				                        ,{field:'tIndex', title:'检测项'}
				                        ,{field:'tStandard', title:'规格'}
				                        ,{field:'upper', title:'上限值'}
				                        ,{field:'lower', title:'下限值'}
				                        ,{field:'tValue', title:'检测值'}
				                        ,{field:'tIndexValue', title:'检测数量'}
				                        ,{field:'tFineValue', title:'检测合格数量'}
				                        ,{field:'tBadValue', title:'检测不合格数量'}
				                        ,{field:'tResult', title:'检测结果'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
			}
		}else if(obj.event === 'delDetails'){
		  layer.confirm('确定删除吗？', function(index){
			var idArr = new Array();
		    var ddId = data.ddId;
		    idArr[0] = ddId;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/disposeRejects/delDisposeRejectsArrDetails.do',
		    	data:{"idArr":idArr},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		}
	});
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	var dNumber = "CZ"+(new Date()).getTime(); // 处置单号
    	var dWay = $("#dWay").val();
    	var dStatus = "0";//订单状态
    	var dApproverStatus = "0";//审批状态
    	var length = $("#tbody tr").length;
    	var x = 0;
    	$("#tbody tr").each(function(i,dom){
    		var tr = $(dom).closest("tr");
			var tds = tr.find("td");
			var ddNumber = tds[1].getElementsByTagName("input")[0].value;
			if(ddNumber != ""){
				x+=1;
			}
    	})
    	if(x==0){
    		toastr.warning('请至少选择一个质检单！');
    	}else{
	    	$.ajax({
				type : "post",
				url : '${pageContext.request.contextPath}/disposeRejects/insertDisposeRejects.do',
				data : {dNumber:dNumber,dWay:dWay,dStatus:dStatus,dApproverStatus:dApproverStatus},
				cache : false,
				async:false
				}).done(
					function(res) {
						if (res > 0) {
							$("#tbody tr").each(function(i,dom){
					    		var tr = $(dom).closest("tr");
								var tds = tr.find("td");
								var ddNumber = tds[1].getElementsByTagName("input")[0].value;
								var ddName = tds[2].getElementsByTagName("input")[0].value;
								var remark01 = tds[3].getElementsByTagName("input")[0].value;
								var remark02 = tds[4].getElementsByTagName("input")[0].value;
								var insDate = tds[5].getElementsByTagName("input")[0].value;
								var testDate = tds[6].getElementsByTagName("input")[0].value;
								var testPerson = tds[7].getElementsByTagName("input")[0].value;
								var badNum = tds[8].getElementsByTagName("input")[0].value;
								$.ajax({
									type : "post",
									url : '${pageContext.request.contextPath}/disposeRejects/insertDisposeRejectsDetails.do',
									data : {dId:res,ddNumber:ddNumber,ddName:ddName,insDate:insDate,testDate:testDate,testPerson:testPerson,badNum:badNum,remark01:remark01,remark02:remark02},
									cache : false,
									async:false
									}).done(
										function(res1) {
											
										}
									)
					    	})
					    	toastr.success('新增成功！');
							$("#subBtn").attr("disabled",true);
							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
								//关闭模态框
								// 父页面刷新
								window.location.reload();  
							},2000);
						}
					}
				).fail(
						function(res) {
							toastr.error('新增失败！');
						}
					) 
    	}
			return false;
    });
});
//查看质检单列表
function selectByDdNumber(index){
	layui.use(['table','layer','upload','form'], function(){
		var table = layui.table;
		var layer = layui.layer,
	    form = layui.form;
		
		var $ = layui.jquery
		layer.open({
	        type: 1 					//Page层类型
	        ,area: ['95%', '600px']   //宽  高
	        ,title: '质检列表'
	        ,shade: 0.6 				//遮罩透明度
	        ,maxmin: true			    //允许全屏最小化
	        ,anim: 1 					//0-6的动画形式，-1不开启
	        /* ,content: $("#lookupTable2") */
	        ,content: '<table class="layui-hide" id="test" lay-filter="test"></table>'
	        ,success:function(){
	            layui.use(['table'], function(){
	                var table = layui.table;
	                table.render({
	                    elem: '#test'
	                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectTestList.do'
	                    ,title: '质检列表'
	                    ,limits:[10,20,30]
	                    ,cols: [[
	                        {field:'tNumber', title:'质检单号'}
	                        ,{field:'tName', title:'名称'}
	                        ,{field:'tCode', title:'条码'}
	                        ,{field:'tStation', title:'工位来源'}
	                        ,{field:'tInsDate', title:'报检日期'}
	                        ,{field:'tTestDate', title:'检验日期'}
	                        ,{field:'tTestPerson', title:'检验人'}
	                        ,{field:'tNum', title:'数目'}
	                    ]]
	                    ,page: true
	                });
	            });
	        }
		})
		table.on('row(test)', function(obj){
			var tNumber = obj.data.tNumber;
			var tStation = obj.data.tStation;
			$.ajax({
				type:'get',
	       		url:'${pageContext.request.contextPath }/disposeRejects/selectTestByNumber.do',
	       		data:{keyword:tNumber},
	       		dataType:'json',
	       		success: function(res){

	       			var trList = $("#tbody").children("tr")
	       			for (var i=0;i<trList.length;i++) {
       			        var tdArr = trList.eq(i).find("td");
       			        var number = tdArr.eq(1).find("input").val();//条码
       			        if(tNumber==number){
       			        	toastr.warning("请选择其他质检单！")
       			        	return;
       			        }
	       			}
					$("#ddNumber"+index).val(tNumber);
	       			$("#ddName"+index).val(res.tName);
	       			$("#remark01"+index).val(res.tCode);
	       			$("#remark02"+index).val(res.tStation);
	       			$("#insDate"+index).val(date2String(res.tInsDate));
	       			$("#testDate"+index).val(date2String(res.tTestDate));
	       			$("#testPerson"+index).val(res.tTestPerson);
	       			$("#badNum"+index).val(res.tNum);
	       			//$("#tWay").val(res.tWay);
	       			layer.close(layer.index);
	       			document.getElementById("ddNumber"+index).onclick = function(){};
	       		}
			})
			$("body").on("click", "#testDetails"+index, function() {
				if(tStation=="检漏工位"){
					layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="evResult" lay-filter="evResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#evResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectLeakHuntingListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'number', title:'质检单号'}
				                        ,{field:'lhCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'bDlNumBig', title:'B面堵漏个数大'}
				                        ,{field:'bDlNumSmall', title:'B面堵漏个数小'}
				                        ,{field:'aDlNumBig', title:'A面堵漏个数大'}
				                        ,{field:'aDlNumSmall', title:'A面堵漏个数小'}
				                        ,{field:'aCount', title:'A面总数'}
				                        ,{field:'bCount', title:'b面总数'}
				                        ,{field:'isNormal', title:'检漏是否正常'}
				                        ,{field:'dmbj', title:'端面补胶'}
				                        ,{field:'describe', title:'非正常问题描述'}
				                        ,{field:'lhResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
				}
			else if(tStation=="组件评价工位"){
					layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="evResult" lay-filter="evResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#evResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectEvaluateListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'number', title:'质检单号'}
				                        ,{field:'evCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'yxsw', title:'运行水温'}
				                        ,{field:'jsyl', title:'进水压力'}
				                        ,{field:'csyl', title:'产水压力'}
				                        ,{field:'nsyl', title:'浓水压力'}
				                        ,{field:'cstl', title:'产水通量'}
				                        ,{field:'nstl', title:'浓水通量'}
				                        ,{field:'yxTime', title:'运行时间'}
				                        ,{field:'evResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
				}else if(tStation=="气密性检测工位"){
					layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="gResult" lay-filter="gResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#gResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectGasListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'number', title:'质检单号'}
				                        ,{field:'gCode', title:'条码'}
				                        ,{field:'facilityNumber', title:'设备编码'}
				                        ,{field:'gIntervalTime', title:'出泡间隔时间',templet:function(row){
				                        	if(row.gIntervalTime==0){
				                        		return "其他";
				                        	}else {
				                        		return row.gIntervalTime;
				                        	}
				                        }}
				                        ,{field:'gResult', title:'检测结果'}
				                        ,{field:'testPerson', title:'检测人'}
				                        ,{field:'testTime', title:'检测时间'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
				}else{
					layer.open({
				        type: 1 					//Page层类型
				        ,area: ['95%', '600px']   //宽  高
				        ,title: '检测结果'
				        ,shade: 0.6 				//遮罩透明度
				        ,maxmin: true			    //允许全屏最小化
				        ,anim: 1 					//0-6的动画形式，-1不开启
				        /* ,content: $("#lookupTable2") */
				        ,content: '<table class="layui-hide" id="testResult" lay-filter="testResult"></table>'
				        ,success:function(){
				            layui.use(['table'], function(){
				                var table = layui.table;
				                table.render({
				                    elem: '#testResult'
				                    ,url:'${pageContext.request.contextPath }/disposeRejects/selectTestListByNumber.do?ptNumber='+tNumber
				                    ,title: '质检列表'
				                    ,limits:[10,20,30]
				                    ,cols: [[
				                        {field:'tNumber', title:'质检单号'}
				                        ,{field:'tIndex', title:'检测项'}
				                        ,{field:'tStandard', title:'规格'}
				                        ,{field:'upper', title:'上限值'}
				                        ,{field:'lower', title:'下限值'}
				                        ,{field:'tValue', title:'检测值'}
				                        ,{field:'tIndexValue', title:'检测数量'}
				                        ,{field:'tFineValue', title:'检测合格数量'}
				                        ,{field:'tBadValue', title:'检测不合格数量'}
				                        ,{field:'tResult', title:'检测结果'}
				                    ]]
				                    ,page: true
				                });
				            });
				        }
					})
				}
			})
		});	
	})
}
//发起审批
function sponsor(){
	$("#sponsorBtn").attr("disabled",true);
	var dId = $("#idApprover").val();
	var dApprover = $("#dApprover").val();
	var dCopyMen = $("#dCopyMen").val();
	var dApproverStatus = "1";//审批状态
	var approvers = dApprover.split(",");
	if(approvers.length!=3){
		toastr.warning("必须选择三层审批！");
	}else{
		var dApprover1 = approvers[0];
		var dApprover2 = approvers[1];
		var dApprover3 = approvers[2];
		$.ajax({
			type: 'post'
			,url: '${pageContext.request.contextPath }/disposeRejects/sponsorApprover.do'
			,data: {dId:dId,dApprover1:dApprover1,dApprover2:dApprover2,dApprover3:dApprover3,dCopyMen:dCopyMen,dApproverStatus:dApproverStatus}
			,success: function(res){
				if(res>0){
					toastr.success("提交成功！");
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
					},2000);
				}else{
					toastr.warning("提交失败！");
				}
			}
		})
	}
}
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>